package o;

import com.tencent.mm.opensdk.modelmsg.WXMediaMessage;
import java.io.EOFException;
import java.io.IOException;
import java.util.Arrays;

public final class adp implements adv {
    private int ʻ;
    private int ʽ;
    private long ˊ;
    private final byte[] ˋ = new byte[4096];
    private final alj ˎ;
    private byte[] ˏ = new byte[WXMediaMessage.THUMB_LENGTH_LIMIT];
    private final long ॱ;

    public adp(alj o_alj, long j, long j2) {
        this.ˎ = o_alj;
        this.ˊ = j;
        this.ॱ = j2;
    }

    public int ˊ(byte[] bArr, int i, int i2) throws IOException, InterruptedException {
        int ॱ = ॱ(bArr, i, i2);
        if (ॱ == 0) {
            ॱ = ˊ(bArr, i, i2, 0, true);
        }
        ॱॱ(ॱ);
        return ॱ;
    }

    public boolean ˊ(byte[] bArr, int i, int i2, boolean z) throws IOException, InterruptedException {
        int ॱ = ॱ(bArr, i, i2);
        while (ॱ < i2 && ॱ != -1) {
            ॱ = ˊ(bArr, i, i2, ॱ, z);
        }
        ॱॱ(ॱ);
        return ॱ != -1;
    }

    public void ˏ(byte[] bArr, int i, int i2) throws IOException, InterruptedException {
        ˊ(bArr, i, i2, false);
    }

    public int ˏ(int i) throws IOException, InterruptedException {
        int ˎ = ˎ(i);
        if (ˎ == 0) {
            ˎ = ˊ(this.ˋ, 0, Math.min(i, this.ˋ.length), 0, true);
        }
        ॱॱ(ˎ);
        return ˎ;
    }

    public boolean ˏ(int i, boolean z) throws IOException, InterruptedException {
        int ˎ = ˎ(i);
        while (ˎ < i && ˎ != -1) {
            ˎ = ˊ(this.ˋ, -ˎ, Math.min(i, this.ˋ.length + ˎ), ˎ, z);
        }
        ॱॱ(ˎ);
        return ˎ != -1;
    }

    public void ॱ(int i) throws IOException, InterruptedException {
        ˏ(i, false);
    }

    public boolean ˎ(byte[] bArr, int i, int i2, boolean z) throws IOException, InterruptedException {
        if (!ˎ(i2, z)) {
            return false;
        }
        System.arraycopy(this.ˏ, this.ʽ - i2, bArr, i, i2);
        return true;
    }

    public void ˎ(byte[] bArr, int i, int i2) throws IOException, InterruptedException {
        ˎ(bArr, i, i2, false);
    }

    public boolean ˎ(int i, boolean z) throws IOException, InterruptedException {
        ˋ(i);
        int i2 = this.ʻ - this.ʽ;
        while (i2 < i) {
            i2 = ˊ(this.ˏ, this.ʽ, i, i2, z);
            if (i2 == -1) {
                return false;
            }
            this.ʻ = this.ʽ + i2;
        }
        this.ʽ += i;
        return true;
    }

    public void ˊ(int i) throws IOException, InterruptedException {
        ˎ(i, false);
    }

    public void ˏ() {
        this.ʽ = 0;
    }

    public long ˎ() {
        return this.ˊ + ((long) this.ʽ);
    }

    public long ˊ() {
        return this.ˊ;
    }

    public long ॱ() {
        return this.ॱ;
    }

    private void ˋ(int i) {
        int i2 = this.ʽ + i;
        if (i2 > this.ˏ.length) {
            this.ˏ = Arrays.copyOf(this.ˏ, anr.ॱ(this.ˏ.length * 2, WXMediaMessage.THUMB_LENGTH_LIMIT + i2, i2 + 524288));
        }
    }

    private int ˎ(int i) {
        int min = Math.min(this.ʻ, i);
        ᐝ(min);
        return min;
    }

    private int ॱ(byte[] bArr, int i, int i2) {
        if (this.ʻ == 0) {
            return 0;
        }
        int min = Math.min(this.ʻ, i2);
        System.arraycopy(this.ˏ, 0, bArr, i, min);
        ᐝ(min);
        return min;
    }

    private void ᐝ(int i) {
        this.ʻ -= i;
        this.ʽ = 0;
        Object obj = this.ˏ;
        if (this.ʻ < this.ˏ.length - 524288) {
            obj = new byte[(this.ʻ + WXMediaMessage.THUMB_LENGTH_LIMIT)];
        }
        System.arraycopy(this.ˏ, i, obj, 0, this.ʻ);
        this.ˏ = obj;
    }

    private int ˊ(byte[] bArr, int i, int i2, int i3, boolean z) throws InterruptedException, IOException {
        if (Thread.interrupted()) {
            throw new InterruptedException();
        }
        int ˋ = this.ˎ.ˋ(bArr, i + i3, i2 - i3);
        if (ˋ != -1) {
            return i3 + ˋ;
        }
        if (i3 == 0 && z) {
            return -1;
        }
        throw new EOFException();
    }

    private void ॱॱ(int i) {
        if (i != -1) {
            this.ˊ += (long) i;
        }
    }
}
